import { createApp } from 'vue'


import App from './App.vue'

const app = createApp(App)

import router from './router'
import installElementPlus from './plugins/element'
import './assets/css/icon.css'

installElementPlus(app)

import axios from 'axios'
let request = axios.create()
request.interceptors.response.use((response) => {
    console.log('axios response', response)
    if (response && response.headers && response.headers.urlprefix) {
        window.url_prefix = response.headers.urlprefix
    }
    return response
},
(err) => {
    console.log('axios error', err)
})
request({
    url:'/index.html',
    method: 'get',
})


import * as ElIconModules from '@element-plus/icons-vue'

Object.keys(ElIconModules).forEach(key => {
app.component(key, ElIconModules[key])
})

app
    .use(router)
    .mount('#app')

window.parse_json = function (v, level, with_lp, parse_is_array) {
    let result = ''
    if (!level) {
        level = 0;
    }

    let t = toString.call(v)
    if (t == '[object Object]') {
        if (parse_is_array) {
            result += '\n'
        }
        if (with_lp) for(let lp = 0; lp < level; lp++) result += '  '
        with_lp = 1
        result += '{\n'
        for(let p in v) {
            if (with_lp) for(let lp = 0; lp <= level; lp++) result += '  '
            if (p == v.length - 1) {
                result += p+': ' + parse_json(v[p], level+1, 0)+'\n'
            } else {
                result += p+': ' + parse_json(v[p], level+1, 0)+',\n'
            }
        }
        if (with_lp) for(let lp = 0; lp < level; lp++) result += '  '
        result += '}'
    } else if (t == '[object Array]') {
        if (with_lp) for(let lp = 0; lp < level; lp++) result += '  '
        with_lp = 1
        result += '['
        for(let p in v) {
            if (with_lp) for(let lp = 0; lp <= level; lp++) result += '  '
            if (p == 0) {
                result += parse_json(v[p], level+1, 1, 1)+',\n'
            } else {
                result += parse_json(v[p], level+1, 0, 0)+',\n'
            }
        }
        if (with_lp) for(let lp = 0; lp < level; lp++) result += '  '
        result += ']'
    } else {
        result += JSON.stringify(v)
    }
    console.log('result', result)
    return result;
    }
